<?php
/**
 * Created by PhpStorm.
 * User: 835173372@qq.com
 * NickName: 孟老师
 * Date: 2017/2/12 22:18
 */
namespace app\app\controller;

use think\Controller;
use think\Db;
use think\Config;

class Base extends Controller{

    //解决跨域--析构方法
    protected function _initialize()
    {
        header('content-type:text/html;charset=utf-8');
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
        header('Access-Control-Allow-Methods: GET, POST, PUT');
        ksort($_POST);
        ksort($_GET);
    }

    //生成token操作
    public function create_token(){
        $token = md5(mt_rand(111111,999999).time());
        return $token;
    }

    //判断用户身份，鉴权操作
    public function is_login(){
        $token = trim($_POST['token']);
        $mid = Db::name('token')->where("token='{$token}'")->value('mid');
        if($mid > 0){
           return $mid;
        }else{
            ajaxmsg('非法数据',0);
        }
    }

}